package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.Creator;
import com.ruoyi.system.service.ICreatorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 装作者管理Controller
 *
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/creator")
public class CreatorController extends BaseController
{
    @Autowired
    private ICreatorService creatorService;

    /**
     * 查询装作者管理列表
     */
    @RequiresPermissions("system:creator:list")
    @GetMapping("/list")
    public TableDataInfo list(Creator creator)
    {
        startPage();
        List<Creator> list = creatorService.selectCreatorList(creator);
        return getDataTable(list);
    }

    /**
     * 导出装作者管理列表
     */
    @RequiresPermissions("system:creator:export")
    @Log(title = "装作者管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Creator creator)
    {
        List<Creator> list = creatorService.selectCreatorList(creator);
        ExcelUtil<Creator> util = new ExcelUtil<Creator>(Creator.class);
        util.exportExcel(response, list, "装作者管理数据");
    }

    /**
     * 获取装作者管理详细信息
     */
    @RequiresPermissions("system:creator:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(creatorService.selectCreatorById(id));
    }

    /**
     * 新增装作者管理
     */
    @RequiresPermissions("system:creator:add")
    @Log(title = "装作者管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Creator creator)
    {
        return toAjax(creatorService.insertCreator(creator));
    }

    /**
     * 修改装作者管理
     */
    @RequiresPermissions("system:creator:edit")
    @Log(title = "装作者管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Creator creator)
    {
        return toAjax(creatorService.updateCreator(creator));
    }

    /**
     * 删除装作者管理
     */
    @RequiresPermissions("system:creator:remove")
    @Log(title = "装作者管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(creatorService.deleteCreatorByIds(ids));
    }
}
